import request from "@/utils/request";

/**
 * 登录
 * @param {string} mobile 手机号码
 * @param {string} data 验证码
 * @returns Promise
 */
export const loginAPI = (mobile, code) => {
  return request({
    url: "/v1_0/authorizations",
    method: "POST",
    data: {
      mobile,
      code
    }
  });
};

/**
 * 路径参数
 * @param {string} mobile 手机号
 * @returns  Promise
 */
// 验证码
export const getCodeAPI = (mobile) => {
  return request({
    url: `/v1_0/sms/codes/${mobile}`
  });
};

/**
 * 路径参数：手动拼接到url上
 * 请求头参数：headers
 * 查询（query）参数（get）params
 * 请求体（body）参数（post，patch，delete）data
 */

// 获取用户信息
export const getUserInfoAPI = () => {
  return request({
    url: "/v1_0/user"
  });
};

/**
 * 获取用户个人信息
 * @returns Promise
 */
export const getUserProfileAPI = () => {
  return request({
    url: "/v1_0/user/profile"
  });
};
/**
 * 编辑用户信息
 * @param {string} data {name,birthday,gender}
 * @returns Promise
 */
export const editUserProfileAPI = (data) => {
  return request({
    url: "/v1_0/user/profile",
    method: "PATCH",
    data
  });
};

/**
 *上传头像
 * @param {string} file 图片文件对象
 * @returns Promise
 */
export const uploadProfileAPI = (file) => {
  const fm = new FormData();
  fm.append("photo", file);
  return request({
    url: "/v1_0/user/photo",
    method: "PATCH",
    data: fm
  });
};
